import { defineStore } from "pinia";
import { reactive } from 'vue';

export const useUserInfoStore = defineStore('userinfo', () => {
  const userinfo = reactive({
    nickName: '',
    avatarUrl: '',
    token: ''
  })

  // 保存信息
  const setUserInfo = (val: any) => {
    console.log(val)
    userinfo.nickName = val.nickName;
    userinfo.avatarUrl = val.avatarUrl;
  }

  // 清楚信息
  const removeUserInfo = () => {
    userinfo.nickName = '';
    userinfo.avatarUrl = '';
    userinfo.token = '';
  }


  return {
    userinfo,
    setUserInfo,
    removeUserInfo
  }
},{
  persist: {
    storage: {
      getItem(key) {
        console.log(key)
        return uni.getStorageSync(key)
      },
      setItem(key, value) {
        uni.setStorageSync(key, value)
      }
    }
  }
})